import ReactDOM from "react-dom";
import React, { Component } from "react";

class Child extends Component {
  render() {
    return <h1>统计豆豆被打的次数：</h1>
  }
}


class App extends Component {

  state = {
    count: 0
  }

  add = () => {
    this.setState({
      count: this.state.count + 1
    })
    // 以下写法不要模仿，只是使用forceUpdate()
    // this.state.count++
    // this.forceUpdate()
  }

  componentDidUpdate() {
    console.log('2. componentDidUpdate')
  }

  render() {
    console.log('1. render')
    return (
      <div className="app">
        {this.state.count}
        <button onClick={this.add}>打豆豆</button>
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("root"));
